package com.banciyuan.bcywebview.biz.topic;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.helper.data.UserDataHelper;
import com.banciyuan.bcywebview.base.helper.timelinedatacenter.DetailDataHelper;
import com.banciyuan.bcywebview.base.helper.timelinedatacenter.TimelineLikeHelper;
import com.banciyuan.bcywebview.base.view.dialog.ConfirmDialog;
import com.banciyuan.bcywebview.base.view.imageview.CircleImageView;
import com.banciyuan.bcywebview.base.view.imageview.SquareImageView;
import com.banciyuan.bcywebview.base.view.textview.SquareTextView;
import com.banciyuan.bcywebview.base.view.toast.MyToast;
import com.banciyuan.bcywebview.biz.circles.CircleLikeHelper;
import com.banciyuan.bcywebview.biz.circles.smooth.CircleSmoothActivity;
import com.banciyuan.bcywebview.biz.circles.smooth.CircleTagSmoothActivity;
import com.banciyuan.bcywebview.biz.detail.goods.GoodsDetailActivity;
import com.banciyuan.bcywebview.biz.groupdetail.NewTeamDetailActivity;
import com.banciyuan.bcywebview.biz.pc.zone.smooth.SmoothPersonActivity;
import com.banciyuan.bcywebview.utils.currency.CurrencyUtil;
import com.banciyuan.bcywebview.utils.http.CommonApiUtils;
import com.banciyuan.bcywebview.utils.http.GifLoader;
import com.banciyuan.bcywebview.utils.http.StatusCodeUtils;
import com.banciyuan.bcywebview.utils.http.VolleyQueue;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;
import com.banciyuan.bcywebview.utils.string.StringUtil;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import java.util.List;

import de.greenrobot.daoexample.model.Circle;
import de.greenrobot.daoexample.model.CirclePost;
import de.greenrobot.daoexample.model.Multi;
import de.greenrobot.daoexample.model.Recommend;
import de.greenrobot.daoexample.model.TopicDetailItem;
import de.greenrobot.daoexample.model.TopicItem;

/**
 * Created by squall on 2015/8/14.
 */
public class TopicDetailAdapter extends BaseAdapter {

    private final int TYPE_NUM = 11;
    private TopicDetailItem topicDetailItem;
    private Context mContext;
    private LayoutInflater inflater;
    private ImageLoader imageLoader;
    private RequestQueue queue;
    private GifLoader gifLoader;
    private boolean isAnimation_runing = false;

    public TopicDetailAdapter(TopicDetailItem topicDetailItem, Context mContext) {
        this.topicDetailItem = topicDetailItem;
        this.mContext = mContext;
        this.inflater = LayoutInflater.from(mContext);
        imageLoader = ImageLoader.getInstance();
        queue = VolleyQueue.getRquest(mContext);
        gifLoader = new GifLoader();
    }

    @Override
    public int getViewTypeCount() {
        return TYPE_NUM;
    }

    @Override
    public int getItemViewType(int position) {
        List<Recommend> rlist = topicDetailItem.getRecommend();
        Recommend recommend = rlist.get(position);
        String type = recommend.getType();
        String subType = recommend.getData().getType();
        return TopicTypeFactory.getTopicType(type, subType);
    }

    @Override
    public int getCount() {
        return topicDetailItem.getRecommend().size();
    }

    @Override
    public Object getItem(int i) {
        return topicDetailItem.getRecommend().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int postion, View view, ViewGroup viewGroup) {

        CosIllView cosIllView = null;
        DailyView dailyView = null;
        PersonView personView = null;
        GroupView groupView = null;
        WritePersonView writePersonView = null;
        WriteView writeView = null;
        GroupPostView groupPostView = null;
        CircleView circleView = null;
        GoodsView goodsView = null;
        ArticleVIew articleVIew = null;
        VideoView videoView = null;
        if (null == view) {
            switch (getItemViewType(postion)) {
                case TopicTypeFactory.TYPE_COSILL:
                    view = inflater.inflate(R.layout.topic_list_item_cosill, viewGroup, false);
                    cosIllView = new CosIllView(view);
                    view.setTag(cosIllView);
                    break;
                case TopicTypeFactory.TYPE_DAILY:
                    view = inflater.inflate(R.layout.topic_list_item_daily, viewGroup, false);
                    dailyView = new DailyView(view);
                    view.setTag(dailyView);
                    break;
                case TopicTypeFactory.TYPE_USER_OTHER:
                    view = inflater.inflate(R.layout.topic_list_item_person, viewGroup, false);
                    personView = new PersonView(view);
                    view.setTag(personView);
                    break;
                case TopicTypeFactory.TYPE_GROUP:
                    view = inflater.inflate(R.layout.topic_list_item_group, viewGroup, false);
                    groupView = new GroupView(view);
                    view.setTag(groupView);
                    break;
                case TopicTypeFactory.TYPE_USER_WRITE:
                    view = inflater.inflate(R.layout.topic_list_item_writeperson, viewGroup, false);
                    writePersonView = new WritePersonView(view);
                    view.setTag(writePersonView);
                    break;
                case TopicTypeFactory.TYPE_WRITE:
                    view = inflater.inflate(R.layout.topic_list_item_write, viewGroup, false);
                    writeView = new WriteView(view);
                    view.setTag(writeView);
                    break;
                case TopicTypeFactory.Type_GROUP_POST:
                    view = inflater.inflate(R.layout.topic_list_item_talk, viewGroup, false);
                    groupPostView = new GroupPostView(view);
                    view.setTag(groupPostView);
                    break;
                case TopicTypeFactory.TYPE_CIRCLE:
                    view = inflater.inflate(R.layout.topic_list_item_circle, viewGroup, false);
                    circleView = new CircleView(view);
                    view.setTag(circleView);
                    break;
                case TopicTypeFactory.TYPE_GOODS:
                    view = inflater.inflate(R.layout.topic_list_item_goods, viewGroup, false);
                    goodsView = new GoodsView(view);
                    view.setTag(goodsView);
                    break;
                case TopicTypeFactory.TYPE_ARTICLE:
                    view = inflater.inflate(R.layout.topic_list_item_article, viewGroup, false);
                    articleVIew = new ArticleVIew(view);
                    view.setTag(articleVIew);
                    break;
                case TopicTypeFactory.TYPE_VIDEO:
                    view = inflater.inflate(R.layout.topic_list_item_video, viewGroup, false);
                    videoView = new VideoView(view);
                    view.setTag(videoView);
                    break;
                default:
                    view = inflater.inflate(R.layout.topic_list_item_cosill, viewGroup, false);
                    cosIllView = new CosIllView(view);
                    view.setTag(cosIllView);
                    break;
            }
        } else {
            switch (getItemViewType(postion)) {
                case TopicTypeFactory.TYPE_COSILL:
                    cosIllView = (CosIllView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_DAILY:
                    dailyView = (DailyView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_USER_OTHER:
                    personView = (PersonView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_GROUP:
                    groupView = (GroupView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_USER_WRITE:
                    writePersonView = (WritePersonView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_WRITE:
                    writeView = (WriteView) view.getTag();
                    break;
                case TopicTypeFactory.Type_GROUP_POST:
                    groupPostView = (GroupPostView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_CIRCLE:
                    circleView = (CircleView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_GOODS:
                    goodsView = (GoodsView) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_ARTICLE:
                    articleVIew = (ArticleVIew) view.getTag();
                    break;
                case TopicTypeFactory.TYPE_VIDEO:
                    videoView = (VideoView) view.getTag();
                    break;
                default:
                    cosIllView = (CosIllView) view.getTag();
                    break;
            }
        }

        switch (getItemViewType(postion)) {
            case TopicTypeFactory.TYPE_COSILL:
                initCosIllItem(cosIllView, postion);
                break;
            case TopicTypeFactory.TYPE_DAILY:
                initDailyItem(dailyView, postion);
                break;
            case TopicTypeFactory.TYPE_USER_OTHER:
                initPersonItem(personView, postion);
                break;
            case TopicTypeFactory.TYPE_GROUP:
                initGroupItem(groupView, postion);
                break;
            case TopicTypeFactory.TYPE_USER_WRITE:
                initWritePersonItem(writePersonView, postion);
                break;
            case TopicTypeFactory.TYPE_WRITE:
                initWriteItem(writeView, postion);
                break;
            case TopicTypeFactory.Type_GROUP_POST:
                initGroupPostItem(groupPostView, postion);
                break;
            case TopicTypeFactory.TYPE_CIRCLE:
                initCircleItem(circleView, postion);
                break;
            case TopicTypeFactory.TYPE_GOODS:
                initGoodsItem(goodsView, postion);
                break;
            case TopicTypeFactory.TYPE_ARTICLE:
                initArticleItem(articleVIew, postion);
                break;
            case TopicTypeFactory.TYPE_VIDEO:
                initVideoView(videoView, postion);
                break;
            default:
                break;
        }

        return view;
    }

    private class GroupPostView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView user_name;
        TextView focus_btn;
        SquareImageView pic1;
        SquareImageView pic2;
        SquareImageView pic3;
        SquareTextView text1;
        SquareTextView text2;
        SquareTextView text3;
        TextView praise_num;
        TextView comment_num;
        TextView from_group;
        TextView content;
        RelativeLayout content_line;
        SquareTextView[] sts;
        SquareImageView[] sis;

        public GroupPostView(View convertView) {
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_talk_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_talk_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_user_pic);
            user_name = (TextView) convertView.findViewById(R.id.topic_talk_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            text1 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_one);
            text2 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_two);
            text3 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_three);
            pic1 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_one);
            pic2 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_two);
            pic3 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_three);
            praise_num = (TextView) convertView.findViewById(R.id.topic_talk_praise);
            comment_num = (TextView) convertView.findViewById(R.id.topic_talk_comment);
            from_group = (TextView) convertView.findViewById(R.id.topic_talk_from);
            content = (TextView) convertView.findViewById(R.id.topic_talk_content);
            content_line = (RelativeLayout) convertView.findViewById(R.id.team_focused_content_rly);
            sts = new SquareTextView[]{text1, text2, text3};
            sis = new SquareImageView[]{pic1, pic2, pic3};
        }
    }

    private class CosIllView extends CardBottomView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView user_name;
        TextView focus_btn;
        SquareImageView main_img;
        TextView pic_num;


        public CosIllView(View convertView) {
            super(convertView);
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_cos_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_cos_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_user_pic);
            user_name = (TextView) convertView.findViewById(R.id.topic_cos_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            main_img = (SquareImageView) convertView.findViewById(R.id.topic_cos_img);
            pic_num = (TextView) convertView.findViewById(R.id.daily_pagenum_tv);
        }
    }

    private class CardBottomView {
        TextView praise_num;
        TextView comment_num;
        TextView recommend_tv;
        ImageView praise_iv;
        RelativeLayout recommendLayout;
        RelativeLayout commentLayout;
        RelativeLayout likeLayout;

        public CardBottomView(View convertView) {
            praise_num = (TextView) convertView.findViewById(R.id.ground_likenumber_tv);
            comment_num = (TextView) convertView.findViewById(R.id.ground_commentnumber_tv);
            recommend_tv = (TextView) convertView.findViewById(R.id.ground_recommend_tv);
            praise_iv = (ImageView) convertView.findViewById(R.id.ground_like_img);
            likeLayout = (RelativeLayout) convertView.findViewById(R.id.ground_like_rly);
            commentLayout = (RelativeLayout) convertView.findViewById(R.id.ground_comment_rly);
            recommendLayout = (RelativeLayout) convertView.findViewById(R.id.ground_recommend_rly);
        }
    }

    private class WriteView extends CardBottomView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView user_name;
        TextView focus_btn;
        TextView main_title;
        TextView main_content;


        public WriteView(View convertView) {
            super(convertView);
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_write_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_write_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_user_pic);
            user_name = (TextView) convertView.findViewById(R.id.topic_write_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            main_title = (TextView) convertView.findViewById(R.id.topic_write_main_title);
            main_content = (TextView) convertView.findViewById(R.id.topic_write_main_text);
        }
    }

    private class GroupView {
        LinearLayout promotion;
        TextView promotion_iv;
        TextView focus_btn;
        TextView main_title;
        TextView sub_title;
        SquareImageView pic1;
        SquareImageView pic2;
        SquareImageView pic3;
        SquareTextView text1;
        SquareTextView text2;
        SquareTextView text3;
        SquareTextView[] sts;
        SquareImageView[] sis;

        public GroupView(View convertView) {
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_group_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_group_promotion_text);
            main_title = (TextView) convertView.findViewById(R.id.topic_group_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            sub_title = (TextView) convertView.findViewById(R.id.topic_group_subtitle);
            text1 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_one);
            text2 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_two);
            text3 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_three);
            pic1 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_one);
            pic2 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_two);
            pic3 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_three);
            sts = new SquareTextView[]{text1, text2, text3};
            sis = new SquareImageView[]{pic1, pic2, pic3};
        }

    }

    private class PersonView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView user_name;
        TextView focus_btn;
        SquareImageView pic1;
        SquareImageView pic2;
        SquareImageView pic3;
        SquareTextView text1;
        SquareTextView text2;
        SquareTextView text3;
        SquareTextView[] sts;
        SquareImageView[] sis;

        public PersonView(View convertView) {
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_person_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_person_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_person_img);
            user_name = (TextView) convertView.findViewById(R.id.topic_person_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            text1 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_one);
            text2 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_two);
            text3 = (SquareTextView) convertView.findViewById(R.id.team_focused_content_tv_three);
            pic1 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_one);
            pic2 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_two);
            pic3 = (SquareImageView) convertView.findViewById(R.id.team_focused_content_img_three);
            sts = new SquareTextView[]{text1, text2, text3};
            sis = new SquareImageView[]{pic1, pic2, pic3};
        }
    }

    private class WritePersonView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView focus_btn;
        TextView main_title;
        TextView sub_content1;
        TextView sub_content2;
        TextView sub_tilte1;
        TextView sub_tilte2;
        TextView[] titles;
        TextView[] contents;

        public WritePersonView(View convertView) {
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_writeperson_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_writeperson_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_writeperson_img);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            main_title = (TextView) convertView.findViewById(R.id.topic_writeperson_title);
            sub_content1 = (TextView) convertView.findViewById(R.id.topic_writeperson_sub1_main);
            sub_content2 = (TextView) convertView.findViewById(R.id.topic_writeperson_sub2_main);
            sub_tilte1 = (TextView) convertView.findViewById(R.id.topic_writeperson_sub1_title);
            sub_tilte2 = (TextView) convertView.findViewById(R.id.topic_writeperson_sub2_title);
            titles = new TextView[]{sub_tilte1, sub_tilte2};
            contents = new TextView[]{sub_content1, sub_content2};
        }
    }

    private class ArticleVIew extends CardBottomView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView user_name;
        TextView focus_btn;
        ImageView pic1;
        TextView content;
        TextView intro;
        TextView author;
        RelativeLayout content_line;
        LinearLayout img_container_one;
        LinearLayout img_container_two;

        public ArticleVIew(View convertView) {
            super(convertView);
            intro = (TextView) convertView.findViewById(R.id.topic_talk_intro);
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_talk_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_talk_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_user_pic);
            user_name = (TextView) convertView.findViewById(R.id.topic_talk_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            pic1 = (ImageView) convertView.findViewById(R.id.daily_content_img);
            content = (TextView) convertView.findViewById(R.id.topic_talk_content);
            content_line = (RelativeLayout) convertView.findViewById(R.id.team_focused_content_rly);
            img_container_one = (LinearLayout) convertView.findViewById(R.id.ll_daily_pics);
            img_container_two = (LinearLayout) convertView.findViewById(R.id.ll_daily_pics_two);
            author = (TextView) convertView.findViewById(R.id.author_name);
        }
    }

    private class VideoView extends CardBottomView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView user_name;
        TextView focus_btn;
        ImageView main_img;
        TextView pic_num;
        TextView title;

        public VideoView(View convertView) {
            super(convertView);
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_video_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_video_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_user_pic);
            user_name = (TextView) convertView.findViewById(R.id.topic_video_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            main_img = (ImageView) convertView.findViewById(R.id.topic_video_img);
            pic_num = (TextView) convertView.findViewById(R.id.daily_pagenum_tv);
            title = (TextView) convertView.findViewById(R.id.video_title);
        }
    }

    private class DailyView extends CardBottomView {
        LinearLayout promotion;
        TextView promotion_iv;
        CircleImageView user_pic;
        TextView user_name;
        TextView focus_btn;
        ImageView pic1;
        SquareImageView pic2;
        SquareImageView pic3;
        SquareImageView pic4;
        SquareImageView pic5;
        TextView content;
        RelativeLayout content_line;
        LinearLayout img_container_one;
        LinearLayout img_container_two;
        ImageView[] sis;
        ImageView[] sis2;

        public DailyView(View convertView) {
            super(convertView);
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_talk_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_talk_promotion_text);
            user_pic = (CircleImageView) convertView.findViewById(R.id.topic_user_pic);
            user_name = (TextView) convertView.findViewById(R.id.topic_talk_title);
            focus_btn = (TextView) convertView.findViewById(R.id.teams_recommend_img);
            pic1 = (ImageView) convertView.findViewById(R.id.daily_content_img_one);
            pic2 = (SquareImageView) convertView.findViewById(R.id.daily_content_img_two);
            pic3 = (SquareImageView) convertView.findViewById(R.id.daily_content_img_three);
            pic4 = (SquareImageView) convertView.findViewById(R.id.daily_content_img_big_one);
            pic5 = (SquareImageView) convertView.findViewById(R.id.daily_content_img_big_two);
            content = (TextView) convertView.findViewById(R.id.topic_talk_content);
            content_line = (RelativeLayout) convertView.findViewById(R.id.team_focused_content_rly);
            img_container_one = (LinearLayout) convertView.findViewById(R.id.ll_daily_pics);
            img_container_two = (LinearLayout) convertView.findViewById(R.id.ll_daily_pics_two);
            sis = new ImageView[]{pic1, pic2, pic3};
            sis2 = new ImageView[]{pic4, pic5};
        }
    }

    private class GoodsView {
        LinearLayout promotion;
        TextView promotion_iv;
        ImageView goodsPic;
        TextView goodsName;
        TextView goodsOwnerName;
        TextView goodsPrice;
        View goodsContainer;

        public GoodsView(View convertView) {
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_goods_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_goods_promotion_text);
            goodsPic = (ImageView) convertView.findViewById(R.id.topic_goods_pic);
            goodsName = (TextView) convertView.findViewById(R.id.topic_goods_name);
            goodsOwnerName = (TextView) convertView.findViewById(R.id.topic_goods_owner_name);
            goodsPrice = (TextView) convertView.findViewById(R.id.topic_goods_price);
            goodsContainer = convertView.findViewById(R.id.topic_goods_view);
        }
    }

    private class CircleView {
        LinearLayout promotion;
        TextView promotion_iv;
        TextView circleName;
        TextView circleWorkNums;
        TextView circleOrderNums;
        TextView circleOrderAction;
        ImageView[] circlePics;
        TextView[] circleTitles;
        TextView[] circleContents;
        View[] circleViews;
        View[] circleTextBgs;
        View[] circleGroupViews;
        View viewParent;
        TextView[] circleGroupTitles;

        public CircleView(View convertView) {
            promotion = (LinearLayout) convertView.findViewById(R.id.topic_circle_promotion);
            promotion_iv = (TextView) convertView.findViewById(R.id.topic_circle_promotion_text);
            circleName = (TextView) convertView.findViewById(R.id.topic_circle_name);
            circleWorkNums = (TextView) convertView.findViewById(R.id.topic_circle_works_num);
            circleOrderNums = (TextView) convertView.findViewById(R.id.topic_circle_order_num);
            circleOrderAction = (TextView) convertView.findViewById(R.id.topic_circle_order_action);
            circlePics = new ImageView[]{(ImageView) convertView.findViewById(R.id.topic_circle_pic_one),
                    (ImageView) convertView.findViewById(R.id.topic_circle_pic_two), (ImageView) convertView.findViewById(R.id.topic_circle_pic_three)};
            circleTitles = new TextView[]{(TextView) convertView.findViewById(R.id.topic_circle_title_one),
                    (TextView) convertView.findViewById(R.id.topic_circle_title_two), (TextView) convertView.findViewById(R.id.topic_circle_title_three)};
            circleContents = new TextView[]{(TextView) convertView.findViewById(R.id.topic_circle_content_one),
                    (TextView) convertView.findViewById(R.id.topic_circle_content_two), (TextView) convertView.findViewById(R.id.topic_circle_content_three)};
            circleViews = new View[]{convertView.findViewById(R.id.topic_contentview_one),
                    convertView.findViewById(R.id.topic_contentview_two), convertView.findViewById(R.id.topic_contentview_three)};
            circleTextBgs = new View[]{convertView.findViewById(R.id.topic_circle_text_bgone),
                    convertView.findViewById(R.id.topic_circle_text_bgtwo), convertView.findViewById(R.id.topic_circle_text_bgthree)};
            View circleGroupViewOne = convertView.findViewById(R.id.group_grid_view_one);
            View circleGroupViewTwo = convertView.findViewById(R.id.group_grid_view_two);
            View circleGroupViewThree = convertView.findViewById(R.id.group_grid_view_three);
            circleGroupViews = new View[]{circleGroupViewOne, circleGroupViewTwo, circleGroupViewThree};
            circleGroupTitles = new TextView[]{(TextView) circleGroupViewOne.findViewById(R.id.item_title),
                    (TextView) circleGroupViewTwo.findViewById(R.id.item_title), (TextView) circleGroupViewThree.findViewById(R.id.item_title)};
            viewParent = convertView.findViewById(R.id.view_parent);
        }
    }

    private void initCosIllItem(final CosIllView cosIllView, final int postion) {

        final Recommend recommend = topicDetailItem.getRecommend().get(postion);

        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), cosIllView.user_pic, ImageOptions.optionHead);
        }
        if (!TextUtils.isEmpty(recommend.getData().getUname())) {
            cosIllView.user_name.setText(recommend.getData().getUname());
        }
        if (TextUtils.isEmpty(recommend.getAbout())) {
            cosIllView.promotion.setVisibility(View.GONE);
        } else {
            cosIllView.promotion.setVisibility(View.VISIBLE);
            cosIllView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                cosIllView.focus_btn.setVisibility(View.VISIBLE);
            } else {
                cosIllView.focus_btn.setVisibility(View.GONE);
            }
        } else {
            cosIllView.focus_btn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getImg_src())) {
            final String url = recommend.getData().getImg_src();
            if (!recommend.getData().getImg_src().contains(".gif")) {
                imageLoader.displayImage(url, cosIllView.main_img, ImageOptions.options);
            } else {
                try {
                    gifLoader.displayGif(url, cosIllView.main_img);
                } catch (OutOfMemoryError e) {
                    e.printStackTrace();
                }
            }
            cosIllView.main_img.setVisibility(View.VISIBLE);
        } else {
            cosIllView.main_img.setVisibility(View.GONE);
        }
        if (recommend.getData().getPic_num() > 0) {
            cosIllView.pic_num.setText(String.valueOf(recommend.getData().getPic_num()));
            cosIllView.pic_num.setVisibility(View.VISIBLE);
        } else {
            cosIllView.pic_num.setVisibility(View.INVISIBLE);
        }

        cosIllView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });
        goPersonDetail(recommend.getData().getUid(), cosIllView.user_name, cosIllView.user_pic);
        godetail(recommend, cosIllView.main_img);

        setBottomData(cosIllView, recommend);
    }

    private void setBottomData(CardBottomView cardBottomView, Recommend recommend) {
        Recommend.InnerData data = recommend.getData();
        if (data.getReply_num() > 0) {
            cardBottomView.comment_num.setText(String.valueOf(data.getReply_num()));
        } else {
            cardBottomView.comment_num.setText(mContext.getString(R.string.comment));
        }
        if (data.isHave_ding()) {
            cardBottomView.praise_iv.setImageResource(R.drawable.like_pink);
            cardBottomView.praise_num.setText(String.valueOf(data.getDing_num()));
        } else {
            cardBottomView.praise_iv.setImageResource(R.drawable.like_grey);
            cardBottomView.praise_num.setText(String.valueOf(data.getDing_num()));
            if (String.valueOf(data.getDing_num()).equals("0")) {
                cardBottomView.praise_num.setText(mContext.getString(R.string.good));
            }
        }
        if (data.isHave_tuijian()) {
            cardBottomView.recommend_tv.setText(mContext.getString(R.string.all_recommended));
        } else {
            cardBottomView.recommend_tv.setText(mContext.getString(R.string.all_recommend));
        }

        Onclick onclick = new Onclick(recommend);
        cardBottomView.likeLayout.setOnClickListener(onclick);
        cardBottomView.recommendLayout.setOnClickListener(onclick);
        cardBottomView.commentLayout.setOnClickListener(onclick);
    }

    private void initVideoView(final VideoView videoView, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);

        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), videoView.user_pic, ImageOptions.optionHead);
        }
        if (!TextUtils.isEmpty(recommend.getData().getUname())) {
            videoView.user_name.setText(recommend.getData().getUname());
        }
        if (TextUtils.isEmpty(recommend.getAbout())) {
            videoView.promotion.setVisibility(View.GONE);
        } else {
            videoView.promotion.setVisibility(View.VISIBLE);
            videoView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                videoView.focus_btn.setVisibility(View.VISIBLE);
            } else {
                videoView.focus_btn.setVisibility(View.GONE);
            }
        } else {
            videoView.focus_btn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getCover())) {
            final String url = recommend.getData().getCover();
            imageLoader.displayImage(url, videoView.main_img, ImageOptions.options);
            videoView.main_img.setVisibility(View.VISIBLE);
        } else {
            videoView.main_img.setVisibility(View.GONE);
        }
        try {
            String time = StringUtil.getTimeDuration((int) Double.parseDouble(recommend.getData().getVideo_info().getDuration()));
            videoView.pic_num.setText(time);
            videoView.pic_num.setVisibility(View.VISIBLE);
        } catch (Exception e) {
            videoView.pic_num.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getTitle())) {
            videoView.title.setVisibility(View.VISIBLE);
            videoView.title.setText(Html.fromHtml(recommend.getData().getTitle()));
        } else {
            videoView.title.setVisibility(View.GONE);
        }
        videoView.praise_num.setText(String.valueOf(recommend.getData().getDing_num()));
        videoView.comment_num.setText(String.valueOf(recommend.getData().getReply_num()));

        videoView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });
        goPersonDetail(recommend.getData().getUid(), videoView.user_name, videoView.user_pic);
        godetail(recommend, videoView.main_img);

        setBottomData(videoView, recommend);
    }

    private void initWriteItem(WriteView writeView, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);
        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), writeView.user_pic, ImageOptions.optionHead);
        }
        writeView.user_name.setText(recommend.getData().getUname());
        if (TextUtils.isEmpty(recommend.getAbout())) {
            writeView.promotion.setVisibility(View.GONE);
        } else {
            writeView.promotion.setVisibility(View.VISIBLE);
            writeView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                writeView.focus_btn.setVisibility(View.VISIBLE);
            } else {
                writeView.focus_btn.setVisibility(View.GONE);
            }
        } else {
            writeView.focus_btn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getTitle())) {
            writeView.main_title.setText(Html.fromHtml(recommend.getData().getTitle()));
        }
        if (!TextUtils.isEmpty(recommend.getData().getContent())) {
            writeView.main_content.setText(Html.fromHtml(recommend.getData().getContent()).toString().trim());
        }
        writeView.praise_num.setText(String.valueOf(recommend.getData().getDing_num()));
        writeView.comment_num.setText(String.valueOf(recommend.getData().getReply_num()));

        writeView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });

        goPersonDetail(recommend.getData().getUid(), writeView.user_name, writeView.user_pic);

        godetailwrite(recommend, writeView.main_content, writeView.main_title);

        setBottomData(writeView, recommend);
    }

    private void initGroupItem(GroupView groupView, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);
        if (TextUtils.isEmpty(recommend.getAbout())) {
            groupView.promotion.setVisibility(View.GONE);
        } else {
            groupView.promotion.setVisibility(View.VISIBLE);
            groupView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getGroup().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getGroup().getFollowstate().equals("unfollow")) {
                groupView.focus_btn.setSelected(false);
            } else {
                groupView.focus_btn.setSelected(true);
            }
        } else {
            groupView.focus_btn.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(recommend.getData().getGroup().getName())) {
            groupView.main_title.setText(Html.fromHtml(recommend.getData().getGroup().getName()));
        }
        if (!TextUtils.isEmpty(recommend.getData().getGroup().getIntro())) {
            groupView.sub_title.setText(Html.fromHtml(recommend.getData().getGroup().getIntro()));
            groupView.sub_title.setVisibility(View.VISIBLE);
        } else {
            groupView.sub_title.setVisibility(View.GONE);
        }
        List<TopicItem> tlist = recommend.getData().getGroup_post();

        if (null != tlist) {
            if (tlist.size() > 0) {
                for (int i = 0; i < groupView.sis.length; i++) {
                    if (i < tlist.size()) {
                        List<Multi> mlist = tlist.get(i).getMulti();
                        if (i < tlist.size()) {
                            if (mlist.size() > 0) {
                                groupView.sis[i].setVisibility(View.VISIBLE);
                                groupView.sts[i].setVisibility(View.INVISIBLE);
                                imageLoader.displayImage(mlist.get(0).getPath(), groupView.sis[i], ImageOptions.options);
                            } else {
                                groupView.sis[i].setVisibility(View.INVISIBLE);
                                groupView.sts[i].setVisibility(View.VISIBLE);
                                groupView.sts[i].setText(Html.fromHtml(tlist.get(i).getPlain()));
                            }
                        } else {
                            groupView.sis[i].setVisibility(View.INVISIBLE);
                            groupView.sts[i].setVisibility(View.INVISIBLE);
                        }
                    }
                }
            } else {
                for (int i = 0; i < groupView.sis.length; i++) {
                    groupView.sis[i].setVisibility(View.GONE);
                    groupView.sts[i].setVisibility(View.GONE);
                }
            }
        }

        groupView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (recommend.getData().getGroup().getFollowstate().equals("unfollow")) {
                    doFocus(recommend.getData().getGroup().getGid(), postion, (TextView) view);
                } else {
                    doCancel(recommend.getData().getGroup().getGid(), postion, (TextView) view);
                }
            }
        });

        goGroup(recommend.getData().getGroup().getGid(),
                recommend.getData().getGroup().getName(),
                groupView.main_title,
                groupView.sub_title,
                groupView.pic1,
                groupView.pic2,
                groupView.pic3,
                groupView.text1,
                groupView.text2,
                groupView.text3);
    }

    private void initPersonItem(PersonView personView, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);
        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), personView.user_pic, ImageOptions.optionHead);
        }
        if (TextUtils.isEmpty(recommend.getAbout())) {
            personView.promotion.setVisibility(View.GONE);
        } else {
            personView.promotion.setVisibility(View.VISIBLE);
            personView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                personView.focus_btn.setVisibility(View.VISIBLE);
            } else {
                personView.focus_btn.setVisibility(View.GONE);
            }
        } else {
            personView.focus_btn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getUname())) {
            personView.user_name.setText(Html.fromHtml(recommend.getData().getUname()));
        }
        List<Recommend.InnerData.Post_data> plist = recommend.getData().getPost_data();

        if (null != plist) {
            if (plist.size() > 0) {
                for (int i = 0; i < personView.sis.length; i++) {
                    if (i < plist.size()) {
                        personView.sis[i].setVisibility(View.VISIBLE);
                        imageLoader.displayImage(plist.get(i).getImg_src(), personView.sis[i], ImageOptions.options);
                    } else {
                        personView.sis[i].setVisibility(View.INVISIBLE);
                    }
                }
            } else {
                for (int i = 0; i < personView.sis.length; i++) {
                    personView.sis[i].setVisibility(View.GONE);
                }
            }
        }

        personView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });

        goPersonDetail(recommend.getData().getUid(),
                personView.user_name,
                personView.user_pic,
                personView.pic1,
                personView.pic2,
                personView.pic3,
                personView.text1,
                personView.text2,
                personView.text3);
    }

    private void initWritePersonItem(WritePersonView writePersonView, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);
        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), writePersonView.user_pic, ImageOptions.optionHead);
        }

        if (TextUtils.isEmpty(recommend.getAbout())) {
            writePersonView.promotion.setVisibility(View.GONE);
        } else {
            writePersonView.promotion.setVisibility(View.VISIBLE);
            writePersonView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                writePersonView.focus_btn.setVisibility(View.VISIBLE);
            } else {
                writePersonView.focus_btn.setVisibility(View.GONE);
            }
        } else {
            writePersonView.focus_btn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getUname())) {
            writePersonView.main_title.setText(Html.fromHtml(recommend.getData().getUname()));
        }
        List<Recommend.InnerData.Post_data> plist = recommend.getData().getPost_data();

        if (null != plist) {
            if (plist.size() > 0) {
                for (int i = 0; i < writePersonView.titles.length; i++) {
                    writePersonView.titles[i].setText(plist.get(i).getTitle());
                    writePersonView.contents[i].setText(Html.fromHtml(plist.get(i).getContent()));
                }
            } else {
                ((View) (writePersonView.sub_tilte1.getParent())).setVisibility(View.GONE);
                ((View) (writePersonView.sub_tilte2.getParent())).setVisibility(View.GONE);
            }
        }

        writePersonView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });

        goPersonDetail(recommend.getData().getUid(),
                writePersonView.main_title,
                writePersonView.user_pic,
                writePersonView.sub_tilte1,
                writePersonView.sub_tilte2,
                writePersonView.sub_content1,
                writePersonView.sub_content2);

    }

    private void initDailyItem(DailyView dailyView, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);
        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), dailyView.user_pic, ImageOptions.optionHead);
        }
        if (!TextUtils.isEmpty(recommend.getData().getUname())) {
            dailyView.user_name.setText(recommend.getData().getUname());
        }
        if (TextUtils.isEmpty(recommend.getAbout())) {
            dailyView.promotion.setVisibility(View.GONE);
        } else {
            dailyView.promotion.setVisibility(View.VISIBLE);
            dailyView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                dailyView.focus_btn.setVisibility(View.VISIBLE);
            } else {
                dailyView.focus_btn.setVisibility(View.GONE);
            }
        } else {
            dailyView.focus_btn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getPlain())) {
            dailyView.content.setText(Html.fromHtml(recommend.getData().getPlain()));
        } else {
            dailyView.content.setVisibility(View.GONE);
        }
        dailyView.praise_num.setText(String.valueOf(recommend.getData().getDing_num()));
        dailyView.comment_num.setText(String.valueOf(recommend.getData().getReply_num()));
        List<Multi> mlist = recommend.getData().getMulti();
        if (null != mlist) {
            if (mlist.size() > 0) {
                dailyView.content_line.setVisibility(View.VISIBLE);
                boolean pic_big = false;
                if (mlist.size() > 2) {
                    dailyView.img_container_one.setVisibility(View.VISIBLE);
                    dailyView.img_container_two.setVisibility(View.GONE);
                    pic_big = true;
                } else if (mlist.size() == 1) {
                    dailyView.img_container_one.setVisibility(View.VISIBLE);
                    dailyView.img_container_two.setVisibility(View.GONE);
                    pic_big = true;
                } else {
                    dailyView.img_container_one.setVisibility(View.GONE);
                    dailyView.img_container_two.setVisibility(View.VISIBLE);
                }
                for (int i = 0; i < dailyView.sis.length; i++) {
                    if (i < mlist.size()) {
                        if (pic_big) {
                            dailyView.sis[i].setVisibility(View.VISIBLE);
                            imageLoader.displayImage(mlist.get(i).getPath(), dailyView.sis[i], ImageOptions.options);
                        } else {
                            dailyView.sis2[i].setVisibility(View.VISIBLE);
                            imageLoader.displayImage(mlist.get(i).getPath(), dailyView.sis2[i], ImageOptions.options);
                        }
                    } else {
                        if (pic_big) {
                            dailyView.sis[i].setVisibility(View.INVISIBLE);
                        }
                    }
                }
            } else {
                dailyView.content_line.setVisibility(View.GONE);
            }
        }
        dailyView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });

        goPersonDetail(recommend.getData().getUid(), dailyView.user_name, dailyView.user_pic);

        if (recommend.getData().getGroup() != null) {
            goGroup(recommend.getData().getGroup().getGid(),
                    recommend.getData().getGroup().getName());
        }

        godetail(recommend,
                dailyView.content,
                dailyView.pic1,
                dailyView.pic2,
                dailyView.pic3,
                dailyView.pic4,
                dailyView.pic5);

        setBottomData(dailyView, recommend);
    }

    private void initArticleItem(ArticleVIew articleVIew, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);
        imageLoader.displayImage(recommend.getData().getCover(), articleVIew.pic1, ImageOptions.options);
        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), articleVIew.user_pic, ImageOptions.optionHead);
        }
        if (!TextUtils.isEmpty(recommend.getData().getUname())) {
            articleVIew.user_name.setText(recommend.getData().getUname());
        }
        if (TextUtils.isEmpty(recommend.getAbout())) {
            articleVIew.promotion.setVisibility(View.GONE);
        } else {
            articleVIew.promotion.setVisibility(View.VISIBLE);
            articleVIew.promotion_iv.setText(recommend.getAbout());
        }
        if (TextUtils.isEmpty(recommend.getData().getUname())) {
            articleVIew.author.setVisibility(View.GONE);
        } else {
            articleVIew.author.setVisibility(View.VISIBLE);
            articleVIew.author.setText(recommend.getData().getUname());
        }

        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && !StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                articleVIew.focus_btn.setVisibility(View.VISIBLE);
            } else {
                articleVIew.focus_btn.setVisibility(View.GONE);
            }
        } else {
            articleVIew.focus_btn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getSummary())) {
            articleVIew.content.setVisibility(View.VISIBLE);
            articleVIew.content.setText(Html.fromHtml(recommend.getData().getSummary()));
        } else {
            articleVIew.content.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(recommend.getData().getTitle())) {
            articleVIew.intro.setVisibility(View.VISIBLE);
            articleVIew.intro.setText(Html.fromHtml(recommend.getData().getTitle()));
        } else {
            articleVIew.intro.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(recommend.getData().getTitle())) {
            articleVIew.intro.setText(Html.fromHtml(recommend.getData().getTitle()));
        } else {
            articleVIew.intro.setVisibility(View.GONE);
        }

        articleVIew.praise_num.setText(String.valueOf(recommend.getData().getDing_num()));
        articleVIew.comment_num.setText(String.valueOf(recommend.getData().getReply_num()));
        articleVIew.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });

        goPersonDetail(recommend.getData().getUid(), articleVIew.user_name, articleVIew.user_pic);

        if (recommend.getData().getGroup() != null) {
            goGroup(recommend.getData().getGroup().getGid(),
                    recommend.getData().getGroup().getName());
        }

        godetail(recommend,
                articleVIew.content,
                articleVIew.pic1,
                (View) (articleVIew.intro.getParent())
        );

        setBottomData(articleVIew, recommend);
    }

    private void initGroupPostItem(GroupPostView groupPostView, final int postion) {
        final Recommend recommend = topicDetailItem.getRecommend().get(postion);
        if (!TextUtils.isEmpty(recommend.getData().getAvatar())) {
            imageLoader.displayImage(recommend.getData().getAvatar(), groupPostView.user_pic, ImageOptions.optionHead);
        }
        if (!TextUtils.isEmpty(recommend.getData().getUname())) {
            groupPostView.user_name.setText(recommend.getData().getUname());
        }
        if (TextUtils.isEmpty(recommend.getAbout())) {
            groupPostView.promotion.setVisibility(View.GONE);
        } else {
            groupPostView.promotion.setVisibility(View.VISIBLE);
            groupPostView.promotion_iv.setText(recommend.getAbout());
        }
        if (!TextUtils.isEmpty(recommend.getData().getFollowstate()) && StringUtil.notNullEqual(recommend.getData().getUid(), UserDataHelper.getInstance(mContext).getUid())) {
            if (recommend.getData().getFollowstate().equals("unfollow")) {
                groupPostView.focus_btn.setVisibility(View.VISIBLE);
            } else {
                groupPostView.focus_btn.setVisibility(View.GONE);
            }
        } else {
            groupPostView.focus_btn.setVisibility(View.GONE);
        }
        if (recommend.getData().getGroup() != null && !TextUtils.isEmpty(recommend.getData().getGroup().getName()))
            groupPostView.from_group.setText(recommend.getData().getGroup().getName());
        if (!TextUtils.isEmpty(recommend.getData().getPlain()))
            groupPostView.content.setText(Html.fromHtml(recommend.getData().getPlain()));
        groupPostView.praise_num.setText(String.valueOf(recommend.getData().getDing_num()));
        groupPostView.comment_num.setText(String.valueOf(recommend.getData().getReply_num()));
        List<Multi> mlist = recommend.getData().getMulti();

        if (null != mlist) {
            if (mlist.size() > 0) {
                groupPostView.content_line.setVisibility(View.VISIBLE);
                for (int i = 0; i < groupPostView.sis.length; i++) {
                    if (i < mlist.size()) {
                        groupPostView.sis[i].setVisibility(View.VISIBLE);
                        imageLoader.displayImage(mlist.get(i).getPath(), groupPostView.sis[i], ImageOptions.options);
                    } else {
                        groupPostView.sis[i].setVisibility(View.INVISIBLE);
                    }
                }
            } else {
                groupPostView.content_line.setVisibility(View.GONE);
            }
        }
        groupPostView.focus_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dofollow(recommend.getData().getUid(), postion, view);
            }
        });

        goPersonDetail(recommend.getData().getUid(), groupPostView.user_name, groupPostView.user_pic);

        if (recommend.getData().getGroup() != null) {
            goGroup(recommend.getData().getGroup().getGid(),
                    recommend.getData().getGroup().getName(),
                    groupPostView.from_group);
        }

        godetail(recommend,
                groupPostView.content,
                groupPostView.pic1,
                groupPostView.pic2,
                groupPostView.pic3,
                groupPostView.text1,
                groupPostView.text2,
                groupPostView.text3);

    }

    private void initCircleItem(final CircleView circleView, final int postion) {
        Recommend recommend = topicDetailItem.getRecommend().get(postion);
        final Circle circle = recommend.getData().getCircle();
        List<CirclePost> circlePost = recommend.getData().getCircle_post();
        if (TextUtils.isEmpty(recommend.getAbout())) {
            circleView.promotion.setVisibility(View.GONE);
        } else {
            circleView.promotion.setVisibility(View.VISIBLE);
            circleView.promotion_iv.setText(recommend.getAbout());
        }
        String followStatus = circle.getFollow_status();
        if (!TextUtils.isEmpty(followStatus)) {
            dealCircleLikeData(circleView, followStatus);
        }
        circleView.circleWorkNums.setText(String.format(mContext.getString(R.string.total_cotent_count),
                circle.getPost_count()));
        circleView.circleOrderNums.setText(String.format(mContext.getString(R.string.unit_focus),
                circle.getFollow_count()));
        circleView.circleName.setText(circle.getName());
        if (null != circlePost) {
            if (circlePost.size() > 0) {
                for (int i = 0; i < circleView.circleViews.length; i++) {
                    if (i < circlePost.size()) {
                        circleView.circleViews[i].setVisibility(View.VISIBLE);
                        CirclePost post = circlePost.get(i);
                        if ("group".equals(post.getType())) {
                            processGroupCircleItem(circleView, post, i);
                        } else
                            processCommonCircleItem(circleView, post, i);
                    } else {
                        circleView.circleViews[i].setVisibility(View.INVISIBLE);
                    }
                }
            }
        }
        circleView.viewParent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (circle.getType().equals("work")) {
                    gotoUtil.gotoAct(mContext, CircleSmoothActivity.class, circle.getName(), circle.getId());
                } else {
                    Intent intent = new Intent(mContext, CircleTagSmoothActivity.class);
                    intent.putExtra(gotoUtil.INTENT_VALUE_ONE, circle.getName());
                    intent.putExtra("type", "tag");
                    mContext.startActivity(intent);
                }
            }
        });
        circleView.circleOrderAction.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        final String status = circle.getFollow_status();
                        String followType = "1".endsWith(status) ? "unfollow" : "follow";
                        CircleLikeHelper.doCircleLike(mContext, circle.getId(), circle.getType(), followType, new CircleLikeHelper.CircleLikeSuccess() {
                            @Override
                            public void onCircleLikeSuccess() {
                                String new_status = status.equals("1") ? "0" : "1";
                                circle.setFollow_status(new_status);
                                dealCircleLikeData(circleView, new_status);
                            }
                        });
                    }
                }
        );
    }

    private void processGroupCircleItem(CircleView circleView, CirclePost circlePost, int i) {
        if (!TextUtils.isEmpty(circlePost.getPlain()))
            circleView.circleGroupTitles[i].setText(Html.fromHtml(circlePost.getPlain()));
        circleView.circleGroupViews[i].setVisibility(View.VISIBLE);
        circleView.circleTextBgs[i].setVisibility(View.GONE);
        if (!TextUtils.isEmpty(circlePost.getCover())) {
            circleView.circlePics[i].setVisibility(View.VISIBLE);
            imageLoader.displayImage(circlePost.getCover(), circleView.circlePics[i], ImageOptions.options);
        } else {
            circleView.circlePics[i].setVisibility(View.INVISIBLE);
        }
    }

    private void processCommonCircleItem(CircleView circleView, CirclePost circlePost, int i) {
        circleView.circleGroupViews[i].setVisibility(View.GONE);
        if (!TextUtils.isEmpty(circlePost.getCover())) {
            circleView.circlePics[i].setVisibility(View.VISIBLE);
            circleView.circleTextBgs[i].setVisibility(View.INVISIBLE);
            imageLoader.displayImage(circlePost.getCover(), circleView.circlePics[i], ImageOptions.options);
        } else {
            circleView.circlePics[i].setVisibility(View.INVISIBLE);
            circleView.circleTextBgs[i].setVisibility(View.VISIBLE);
            if (!TextUtils.isEmpty(circlePost.getPlain())) {
                circleView.circleTitles[i].setVisibility(View.GONE);
                circleView.circleContents[i].setTextColor(mContext.getResources().getColor(R.color.mine_textcolor));
                circleView.circleContents[i].setText(Html.fromHtml(circlePost.getPlain()));
            } else {
                if (!TextUtils.isEmpty(circlePost.getTitle())) {
                    circleView.circleTitles[i].setVisibility(View.VISIBLE);
                    circleView.circleTitles[i].setText(Html.fromHtml(circlePost.getTitle()));
                }
                circleView.circleContents[i].setTextColor(mContext.getResources().getColor(R.color.grey_ten_level));
                if (!TextUtils.isEmpty(circlePost.getContent()))
                    circleView.circleContents[i].setText(Html.fromHtml(circlePost.getContent()));
            }
        }
    }

    private void initGoodsItem(GoodsView goodsView, int postion) {
        Recommend recommend = topicDetailItem.getRecommend().get(postion);
        if (TextUtils.isEmpty(recommend.getAbout())) {
            goodsView.promotion.setVisibility(View.GONE);
        } else {
            goodsView.promotion.setVisibility(View.VISIBLE);
            goodsView.promotion_iv.setText(recommend.getAbout());
        }
        final Recommend.InnerData data = recommend.getData();
        imageLoader.displayImage(data.getCover(), goodsView.goodsPic, ImageOptions.options);
        goodsView.goodsName.setText(data.getTitle());
        goodsView.goodsOwnerName.setText(String.format(mContext.getString(R.string.by_name_format), data.getUname()));
        goodsView.goodsPrice.setText(String.format(mContext.getString(R.string.price_format), CurrencyUtil.getMoney(data.getBasic_price())));
        goodsView.goodsContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gotoUtil.gotoAct(mContext, GoodsDetailActivity.class, data.getZg_id());
            }
        });
    }

    private void dealCircleLikeData(CircleView circleView, String followStatus) {
        if (followStatus.equals("1")) {
            circleView.circleOrderAction.setSelected(true);
        } else {
            circleView.circleOrderAction.setSelected(false);
        }
    }

    public void doFocus(final String mGid, final int postion, final TextView view) {
        Response.Listener<String> onSuccess = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if (StatusCodeUtils.dealStatusCode(response, mContext)) {
                    MyToast.show(mContext, mContext.getString(R.string.focus_succ));
                    topicDetailItem.getRecommend().get(postion).getData().getGroup().setFollowstate("follow");
                    view.setSelected(!view.isSelected());
                }
            }
        };
        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        };
        CommonApiUtils.doTeamFollow(mContext, queue, onSuccess, onError, mGid);
    }

    private void doCancel(final String mGid, final int postion, final TextView view) {
        ConfirmDialog.Builder builder = new ConfirmDialog.Builder(mContext);
        builder.setDescString(mContext.getString(R.string.comfirm_unfollow))
                .setActionString(mContext.getString(R.string.mydialog_comfirm))
                .setCancelString(mContext.getString(R.string.mydialog_cancel))
                .setActionClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        doUnFocus(mGid, postion, view);
                    }
                }).create().show();
    }

    public void doUnFocus(final String mGid, final int postion, final TextView view) {
        Response.Listener<String> onSuccess = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if (StatusCodeUtils.dealStatusCode(response, mContext)) {
                    MyToast.show(mContext, mContext.getString(R.string.cancle_focus_succ));
                    topicDetailItem.getRecommend().get(postion).getData().getGroup().setFollowstate("unfollow");
                    view.setSelected(!view.isSelected());
                }
            }
        };
        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        };
        CommonApiUtils.doTeamCancel(mContext, queue, onSuccess, onError, mGid);
    }

    public void dofollow(final String uid, final int postion, final View view) {
        TimelineLikeHelper.doFollow(mContext, "dofollow", uid, new TimelineLikeHelper.FollowSuccess() {
            @Override
            public void onFollowSuccess(String response) {
                MyToast.show(mContext, mContext.getString(R.string.focus_succ));
                topicDetailItem.getRecommend().get(postion).getData().setFollowstate("havafollow");
                view.setVisibility(View.GONE);
            }
        });
    }

    private void goPersonDetail(final String uid, View... view) {

        View.OnClickListener click = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                gotoUtil.gotoAct(mContext, SmoothPersonActivity.class, uid);
            }
        };
        for (int i = 0; i < view.length; i++) {
            view[i].setOnClickListener(click);
        }
    }

    private void goGroup(final String gid, final String name, View... view) {
        View.OnClickListener click = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                gotoUtil.gotoAct(mContext, NewTeamDetailActivity.class, gid, name);
            }
        };
        for (int i = 0; i < view.length; i++) {
            view[i].setOnClickListener(click);
        }
    }

    private void godetail(final Recommend recommend, View... view) {
        View.OnClickListener click = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    if (!TextUtils.isEmpty(recommend.getType())) {
                        if (recommend.getType().equals("cos")) {
                            DetailDataHelper.gotoCosDetail(mContext, recommend.getData().getRp_id(), recommend.getData().getCp_id(), false);
                        } else if (recommend.getType().equals("illust")) {
                            DetailDataHelper.gotoDrawerDetail(mContext, recommend.getData().getRp_id(), recommend.getData().getDp_id(), false);
                        } else if (recommend.getType().equals("novel")) {
                            DetailDataHelper.gotoWriterDetail(mContext, recommend.getData().getRp_id(), recommend.getData().getWp_id(), false);
                        } else if (recommend.getType().equals("group_post")) {
                            DetailDataHelper.gotoGroupDetail(mContext, recommend.getData().getGroup().getGid(), recommend.getData().getPost_id(), false);
                        } else if (recommend.getType().equals("daily")) {
                            DetailDataHelper.gotoDailyDetail(mContext, recommend.getData().getUd_id(), false);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        for (int i = 0; i < view.length; i++) {
            view[i].setOnClickListener(click);
        }
    }

    private void godetailwrite(final Recommend recommend, View... view) {
        View.OnClickListener click = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    DetailDataHelper.gotoWriterDetail(mContext, recommend.getData().getRp_id(), recommend.getData().getWp_id(), false);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        for (int i = 0; i < view.length; i++) {
            view[i].setOnClickListener(click);
        }
    }

    class Onclick implements View.OnClickListener {
        private Recommend recommend;
        private Recommend.InnerData mItem;
        String type;
        String subType;
        int timelineType;

        public Onclick(Recommend recommend) {
            this.recommend = recommend;
            mItem = this.recommend.getData();
            type = recommend.getType();
            subType = recommend.getData().getType();
            timelineType = TopicTypeFactory.getTopicType(type, subType);
        }

        @Override
        public void onClick(final View v) {
            switch (v.getId()) {
                case R.id.ground_comment_rly:

                    switch (timelineType) {
                        case TopicTypeFactory.TYPE_COSILL:
                            if ("cos".equals(type))
                                DetailDataHelper.gotoCosDetail(mContext, mItem.getRp_id(), mItem.getCp_id(), true);
                            else if ("illust".equals(type))
                                DetailDataHelper.gotoDrawerDetail(mContext, mItem.getRp_id(), mItem.getDp_id(), true);
                            break;
                        case TopicTypeFactory.TYPE_DAILY:
                        case TopicTypeFactory.TYPE_ARTICLE:
                        case TopicTypeFactory.TYPE_VIDEO:
                            DetailDataHelper.gotoDailyDetail(mContext, mItem.getUd_id(), true);
                            break;
                        case TopicTypeFactory.TYPE_WRITE:
                            DetailDataHelper.gotoWriterDetail(mContext, mItem.getRp_id(), mItem.getWp_id(), true);
                            break;
                    }
                    break;
                case R.id.ground_recommend_rly:
                    TimelineLikeHelper.doRecommendAll(mContext, VolleyQueue.getRquest(mContext),
                            DetailDataHelper.parseRecommenndToDetailType(mItem, type),
                            String.valueOf(mItem.isHave_tuijian()), new TimelineLikeHelper.TimelineSuccess() {
                                @Override
                                public void onTimelineSuccess() {
                                    mItem.setHave_tuijian(!mItem.isHave_tuijian());
                                    renderRecommend(v, mItem);
                                }
                            });
                    break;
                case R.id.ground_like_rly:
                    if (isAnimation_runing) break;
                    TimelineLikeHelper.doLikeAll(mContext, VolleyQueue.getRquest(mContext),
                            DetailDataHelper.parseRecommenndToDetailType(mItem, type),
                            String.valueOf(mItem.isHave_ding()), new TimelineLikeHelper.TimelineSuccess() {
                                @Override
                                public void onTimelineSuccess() {
                                    if (!mItem.isHave_ding()) {
                                        mItem.setDing_num(StringUtil.getString(
                                                StringUtil.getInt(mItem.getDing_num()) + 1));
                                    } else {
                                        mItem.setDing_num(StringUtil.getString(
                                                StringUtil.getInt(mItem.getDing_num()) - 1));
                                    }
                                    mItem.setHave_ding(!mItem.isHave_ding());
                                    renderPaise(v, mItem);
                                }
                            });
                    break;
            }
        }
    }

    private void renderPaise(View view, final Recommend.InnerData item) {
        final ImageView iv = (ImageView) view.findViewById(R.id.ground_like_img);
        final TextView tv = (TextView) view.findViewById(R.id.ground_likenumber_tv);
        if (item.isHave_ding()) {
            isAnimation_runing = true;
            iv.setScaleY(2f);
            iv.setScaleX(2f);
            iv.setImageResource(R.drawable.frame_praise);
            AnimationDrawable drawable = (AnimationDrawable) iv.getDrawable();
            drawable.start();
            iv.postDelayed(new Runnable() {
                @Override
                public void run() {
                    iv.setScaleY(1f);
                    iv.setScaleX(1f);
                    iv.setImageResource(R.drawable.like_pink);
                    tv.setText(item.getDing_num());
                    isAnimation_runing = false;
                }
            }, 24 * 20);
        } else {
            iv.setImageResource(R.drawable.like_grey);
            tv.setText(item.getDing_num());
            if (item.getDing_num().equals("0")) {
                tv.setText(mContext.getString(R.string.good));
            }
        }
    }

    private void renderRecommend(View view, Recommend.InnerData item) {
        TextView tv = (TextView) view.findViewById(R.id.ground_recommend_tv);
        if (item.isHave_tuijian()) {
            tv.setText(mContext.getString(R.string.all_recommended));
        } else {
            tv.setText(mContext.getString(R.string.all_recommend));
        }
    }

}
